package one.stand.event;

import com.jmp.base.dto.SunCodeDeleteRequest;
import com.jmp.feign.SunCodeFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

@Component
@Async("asyncServiceExecutor")
@Slf4j
public class PlatformChildAddEventListener {
    @Autowired
    private SunCodeFeign sunCodeFeign;

    @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
    public void hanldeEvent(PlatformChildAddEvent event) {
        log.info("{}", event.getSource());

        SunCodeDeleteRequest sunCodeDeleteRequest = SunCodeDeleteRequest.builder()
                .companyId(event.getCompanyId())
                .build();
        sunCodeFeign.delete(sunCodeDeleteRequest);
    }
}
